<template>
	<view class="goods-item">
		<!-- 商品左侧图片区域 -->
		<view class="goods-item-left">
			<radio :checked="goods.goods_state" color="#c00000" v-if="showRadio" @click="radioClickHandler"></radio>
			<image :src="goods.goods_small_logo || defaulPic" mode="widthFix"></image>
		</view>
		<!-- 商品右侧信息区域 -->
		<view class="goods-item-right">
			<!-- 商品标题 -->
			<view class="goods-name">
				{{goods.goods_name}}
			</view>
			<!-- 商品价格和数量 -->
			<view class="goods-prinum">
				<view class="goods-price">
					￥{{goods.goods_price | tofixed}}
				</view>
				<uni-number-box :min="1" v-if="showNumber" :value="goods.goods_count" @change="numChange" />
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		props: {
			//商品信息
			goods: {
				tye: Object,
				default: {}
			},
			// 是否展示图片左侧 的radio
			showRadio: {
				type: Boolean,
				//如果没有外界 制定的show-radio属性值，默认不展示 radio组件
				default: false
			},
			showNumber: {
				type: Boolean,
				//如果没有外界 制定的show-radio属性值，默认不展示 radio组件
				default: false
			}
		},
		filters: {
			tofixed(num) {
				return Number(num).toFixed(2)
			}
		},
		methods: {
			radioClickHandler() {
				this.$emit('radio-change', {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},
			numChange(e) {
				this.$emit('number-change', {
					goods_id: this.goods.goods_id,
					goods_count: e
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		display: flex;
		height: 210rpx;
		margin: 5px;
		border-bottom: 1px #ebebeb solid;

		.goods-item-left {
			width: 30%;
			padding: 10px;
			display: flex;
			margin-right: 5px;
			justify-content: space-between;
			align-items: center;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.goods-item-right {
			width: 70%;
			margin-left: 10px;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding: 10px;

			.goods-name {
				font-size: 14px;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 3;
				-webkit-box-orient: vertical;
			}

			.goods-prinum {
				display: flex;
				justify-content: space-between;

				.goods-price {
					font-size: 16px;
					color: #8d3a4d;
				}
			}
		}
	}
</style>
